package org.carabiner.infinitest.swingui;

import java.awt.event.ActionEvent;

import javax.swing.AbstractAction;
import javax.swing.Action;
import javax.swing.Icon;
import javax.swing.ImageIcon;

import org.carabiner.infinitest.InfinitestCore;

/**
 * 
 * @author <a href="mailto:benrady@gmail.com"Ben Rady</a>
 */
class HaltTestAction extends AbstractAction
{
  private InfinitestCore core;
  private ImageIcon stopIcon;
  private ImageIcon startIcon;
  
  public HaltTestAction(InfinitestCore infinitestCore)
  {
    core = infinitestCore;
    stopIcon = new ImageIcon(HaltTestAction.class.getResource("stop.png"));
    startIcon = new ImageIcon(HaltTestAction.class.getResource("rerun.png"));    
    setIcon();    
  }

  private void setIcon()
  {
    if (core.shouldRunTests())
    {
      putValue(Action.SMALL_ICON, stopIcon);
      putValue(Action.SHORT_DESCRIPTION, "Stop running the tests");
    }
    else
    {
      putValue(Action.SMALL_ICON, startIcon);
      putValue(Action.SHORT_DESCRIPTION, "Start running the tests");
    }
  }
  
  public void actionPerformed(ActionEvent e)
  { 
    core.setRunTests(!core.shouldRunTests());
    setIcon();
  }
}
